package com.br.unisal.library.view.graphic;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import com.br.unisal.library.view.LibraryOperations;
import com.br.unisal.library.view.LibraryOperationsInterface;

public class MainMenuGraphicView extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private final JButton btnEmprstimo = new JButton("Empr\u00E9stimo");
	private final JButton btnDevolucao = new JButton("Devolu\u00E7\u00E3o");
	private final JButton btnBuscar = new JButton("Buscar");
	private final JButton btnCadastrar = new JButton("Cadastrar");
	private LibraryOperationsInterface operations = new LibraryOperations();
	private final JButton btnLogout = new JButton("Logout");

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainMenuGraphicView frame = new MainMenuGraphicView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainMenuGraphicView() {
		initGUI();
	}
	private void initGUI() {
		setTitle("Biblioteca Unsial");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(btnEmprstimo)
							.addGap(18)
							.addComponent(btnDevolucao, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnBuscar, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(btnCadastrar, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))
						.addComponent(btnLogout))
					.addContainerGap(20, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(21)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnDevolucao)
						.addComponent(btnBuscar)
						.addComponent(btnCadastrar)
						.addComponent(btnEmprstimo))
					.addPreferredGap(ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
					.addComponent(btnLogout)
					.addGap(52))
		);
		contentPane.setLayout(gl_contentPane);
		
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				doLogout();
			}
		});
		
		btnEmprstimo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				doLending();
			}
		});
	}
	
	private void doLending() {
		this.operations.lend();
	}
	
	private void doDevolution() {
		//TODO implement
	}
	
	private void doSearch() {
		//TODO implement
	}
	
	private void doRegister() {
		//TODO implement
	}
	
	private void doLogout() {
		//TODO implement
	}

}
